package org.jsona4j.tests.group1;

import java.io.File;
import java.io.FileReader;
import java.util.Map.Entry;

import org.jsona4j.annotations.UnMarshaller;

import junit.framework.TestCase;

public class Group1Tests extends TestCase {

	public void testOne() throws Exception {
		File f = new File("samples/trends.json");
		
		TrendList tlist = UnMarshaller.unmarshall(TrendList.class, new FileReader(f));
		
		assertNotNull(tlist.asOf);
		assertNotNull(tlist.trends);
		assertTrue(tlist.trends.size() > 0);
		
		for (LinkableTrend trend : tlist.trends) {
			assertNotNull("trend is null", trend);
			assertNotNull("trend.name is null", trend.name);
			assertNotNull("trend.url is null", trend.url);
			assertNull("trend.query is not null", trend.query);
		}
	}
	
	public void testTwo() throws Exception {
		File f = new File("samples/trends.current.json");
		
		PublicTrendList tlist = UnMarshaller.unmarshall(PublicTrendList.class, new FileReader(f));
		
		assertNotNull(tlist.asOf);
		assertNotNull(tlist.trends);
		assertTrue(tlist.trends.size() > 0);
		
		for (Entry<TrendDate, Trend[]> entry : tlist.trends.entrySet()) {
			
			assertNotNull(entry.getKey().date);
			
			for (Trend trend : entry.getValue()) {
				assertNotNull("trend is null", trend);
				assertNotNull("trend.name is null", trend.name);
				assertNotNull("trend.query is null", trend.query);
			}
		}
	}
}
